package com.hgxd.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hgxd.annotation.OperationLogAnnotation;
import com.hgxd.service.IEquipmentAlarmService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;
import java.util.List;

import com.hgxd.result.Result;


import com.hgxd.entity.pojo.EquipmentAlarm;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 设备报警表 前端控制器
 * </p>
 *
 * @author fsd
 * @since 2023-10-18
 */
@Api(tags = "设备报警表")
@RestController
@RequestMapping("/api/equipment-alarm")
@CrossOrigin
public class EquipmentAlarmController {
    @Resource(name = "EquipmentAlarmServiceImpl")
    private IEquipmentAlarmService equipmentAlarmService;

    /**
     * 查询所有报警数量(大屏用)
     */
    @GetMapping("/getCountEquipmentAlarm")
    @ApiOperation(value = "查询所有报警数量", notes = "查询所有报警数量")
    @OperationLogAnnotation(operModule = "设备报警表-查询所有报警数量", operType = "查询", operContent = "查询所有报警数量")
    public Result<Integer> getCountEquipmentAlarm() {
        return Result.ok(equipmentAlarmService.list().size());
    }

    /**
     * 新增
     */
    @PostMapping("/save")
    @ApiOperation(value = "设备报警的新增", notes = "设备报警的新增")
    @ApiImplicitParam(name = "equipmentAlarm", value = "设备报警实体类")
    @OperationLogAnnotation(operModule = "设备报警表-新增", operType = "新增", operContent = "新增设备报警")
    public Result<Boolean> insert(@RequestBody EquipmentAlarm equipmentAlarm) {
        return Result.ok(equipmentAlarmService.save(equipmentAlarm));
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation(value = "设备报警的修改", notes = "设备报警的修改")
    @ApiImplicitParam(name = "equipmentAlarm", value = "设备报警实体类")
    @OperationLogAnnotation(operModule = "设备报警表-修改", operType = "修改", operContent = "修改设备报警")
    public Result<Boolean> update(@RequestBody EquipmentAlarm equipmentAlarm) {
        return Result.ok(equipmentAlarmService.updateById(equipmentAlarm));
    }

    /**
     * 批量删除
     */
    @PostMapping("/del/batch")
    @ApiOperation(value = "设备报警的批量删除", notes = "设备报警的批量删除")
    @ApiImplicitParam(name = "ids", value = "id数组")
    @OperationLogAnnotation(operModule = "设备报警表-批量删除", operType = "删除", operContent = "批量删除设备报警")
    public Result<Boolean> deleteBatch(@RequestBody List<Integer> ids) {
        return Result.ok(equipmentAlarmService.removeByIds(ids));
    }

    /**
     * 查询全部
     */
    @GetMapping("/getAll")
    @ApiOperation(value = "查询全部设备报警", notes = "查询全部设备报警")
    @OperationLogAnnotation(operModule = "设备报警表-查询全部", operType = "查询", operContent = "查询全部设备报警")
    public Result<List<EquipmentAlarm>> findAll() {
        return Result.ok(equipmentAlarmService.list());
    }


    /**
     * 分页模糊查询
     */
    @PostMapping("/get/page")
    @ApiOperation(value = "分页模糊查询设备报警", notes = "分页模糊查询设备报警")
//    @ApiImplicitParam(name = "", value = "")
    @OperationLogAnnotation(operModule = "设备报警表-分页模糊查询", operType = "查询", operContent = "分页模糊查询设备报警表")
    public Result findPage(@RequestParam Integer pageNum,
                           @RequestParam Integer pageSize) {
        QueryWrapper<EquipmentAlarm> queryWrapper = new QueryWrapper<>();
        // 倒序查询
        queryWrapper.orderByDesc("id");
        return Result.ok(equipmentAlarmService.page(new Page<>(pageNum, pageSize), queryWrapper));
    }
}

